#!/usr/bin/python
# encoding: utf-8
'''
@File    :   dingyihanshu.py
@Time    :   2020/03/12 00:40:38
@Author  :   fangkaijin 
@Version :   1.0
@Contact :   fangkaijin@gmail.com
@License :   杭州移动互联
@Desc    :   None
'''

# 导入库包
import sys, os, unicodedata
import math
import builtins
import lzo

#isinstance() 函数判断参数是否为某些类型
def my_abs(x):
    if not isinstance(x, (int, float)):
        return '不是数字'
    if x > 0:
        return x
    else:
        return -x

#print(abs(1))

print(my_abs('四'))
print(my_abs(u'-123'))
print(my_abs(u'abs'))
print(my_abs(123))
print(my_abs(-9))


#返回多个值
def move(x, y, z, step, angle = 0):
    nx = x + step * math.cos(angle)
    ny = y - step * math.sin(angle)
    return nx, ny

x, y = move(100, 100, 60, math.pi / 6)
print(x, y)

def power(x, n = 2):
    if not isinstance(x, (int, float)):
        return 'x不是数字'
    if not isinstance(n, (int, float)):
        return 'n不是数字'
    sum = 1   
    for n in range(n):
        sum = sum * x
    return '结果是'+str(sum)

print(power(2, 4))
print(power('1', 3))
print(power(5))

def appendEnd(l=None):
    if l is None:
        l = []
    l.append('end')
    return l

print(appendEnd([1,2,3,4]))
print(appendEnd())
print(appendEnd())

#可变参数
def sum(*numbers):
    sum = 0
    for n in numbers:
        sum += n
    return sum

print(sum(1,2,3,4,5,6,7,8,9,10))
#nums = [1,2,3,4,5,6,7,8,9,10]
#nums = (1,2,3,4,5,6,7,8,9,10)
nums = set([1,2,3,4,5,6,7,8,9,10])
print(sum(*nums))

#关键字参数
def person(name, age, **kw):
    return name, age,  kw

print(person('小红', 36))